package 线程停止;
class MyObject
{
	private String username="1";
	private String password="11";
	public void setValue(String u,String p)
	{
		this.username=u;
		
		if(Thread.currentThread().getName().equals("a"));
		{
			System.out.println("停止a线程");
			Thread.currentThread().suspend();
			//Thread.yield();
		}
		this.password=p;
		
	}
	public void printUsernamePassword()
	{
	System.out.println(username+" "+password);
	}
}
public class Test1_50 {
//在使用suspend与resume方法时也容易出现因为线程的暂停而导致数据不同步的情况
	public static void main(String[] args) throws InterruptedException{
		// TODO Auto-generated method stub
		final MyObject myobject=new MyObject();
		Thread thread1=new Thread() {
			public void run()
			{
				myobject.setValue("a", "aa");//设置线程使用方式
			};
		};
		thread1.setName("a");
		thread1.start();
		Thread.sleep(500);
		Thread thread2=new Thread() {
			public void run()
			{
				myobject.printUsernamePassword();
			};
		};
		thread2.start();
		

	}

}
